<?php

  echo '<h3>Existing files</h3>';

  echo '<div id="php">';
  echo '<p><b>CMS page files (click to edit):</b></p>';
  echo "\n<ul>\n";
  echo '<li><a href="/~mascot/cms/admin/write.php?page=index" title="Edit">index.php</a></li>';
  $dirname = "../";
  $dh = opendir($dirname);
  $filesArray1 = array();
  while (false !== ($file = readdir($dh))) {
    // Select .php files
    if (strstr($file, '.php')) {
      // Add each file to array
      $filesArray1[] = $file;
    }
  }
  // Sort alphabetically
  natcasesort($filesArray1);
  foreach ($filesArray1 as $file) {
    $edit_me = str_replace(".php", "", $file);
    print '<li><a href="/~mascot/cms/admin/write.php?page=' . $edit_me . '" title="Edit">' . $file . '</a></li>';
  }
  closedir($dh);
  echo "\n</ul>\n";
  echo '</div>';

  echo '<div id="txt">';
  echo '<p><b>Corresponding text files:</b></p>';
  echo "\n<ul>\n";
  echo '<li><a href="../textfiles/index.txt" title="View">index.txt</a></li>';
  $dirname = "../textfiles";
  $dh = opendir($dirname);
  $filesArray2 = array();
  while (false !== ($file = readdir($dh))) {
    // Select .txt files
    if (strstr($file, '.txt')) {
      // Add each file to array
      $filesArray2[] = $file;
    }
  }
  // Sort alphabetically
  natcasesort($filesArray2);
  foreach ($filesArray2 as $file) {
    if ($file !== 'index.txt') {
      print '<li><a href="../textfiles/' . $file . '" title="View">' . $file . '</a></li>';
    }
  }
  closedir($dh);
  echo "\n</ul>\n";
  echo '</div>';

?>
